package com.yxx.controller.admin;

import com.yxx.medicinecommon.result.PageResult;
import com.yxx.medicinecommon.result.ResponseResult;
import com.yxx.medicinepojo.dto.ChineseMedicineDTO;
import com.yxx.medicinepojo.dto.ChineseMedicinePageQueryDTO;
import com.yxx.medicinepojo.dto.ChineseWesternMedicineDTO;
import com.yxx.medicinepojo.dto.ChineseWesternMedicinePageQueryDTO;
import com.yxx.medicinepojo.vo.ChineseMedicineVO;
import com.yxx.medicinepojo.vo.ChineseWesternMedicineVO;
import com.yxx.service.ChineseMedicineService;
import com.yxx.service.ChineseWesternMedicineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 中药管理
 * @author yuxiangxun
 * @date 2024/9/21
 * @apiNote
 */
@RestController
@RequestMapping("/admin/chinesemedicine")
@Slf4j
@Api(tags = "中药管理")
public class ChineseMedicineController {
    @Autowired
    private ChineseMedicineService chineseMedicineService;

    /**
     * 中西药分类
     * @param chineseMedicinePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("中药分页")
    public ResponseResult<PageResult> ChineseMedicinePage(
            @ApiParam(value = "中药分页数据",required = true)
            ChineseMedicinePageQueryDTO chineseMedicinePageQueryDTO){
        PageResult page = chineseMedicineService.chineseMedicinePage(chineseMedicinePageQueryDTO);
        return ResponseResult.success(page);
    }

    @GetMapping("/list")
    @ApiOperation("根据分类id查询中药")
    public ResponseResult<List<ChineseMedicineVO>> ChineseMedicineList(
            @ApiParam(value = "中药分类id", required = true) Long categoryId,
            @ApiParam(value = "中药名称",required = true) String name){
        log.info("categoryId",categoryId);
        List<ChineseMedicineVO> list = chineseMedicineService.list(categoryId,name);
        log.info("list<ChineseMedicineList> = ",list.toString());
        return ResponseResult.success(list);
    }

    /**
     * 中/西药上线下架
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("中药上线下架")
    public ResponseResult startOrstop(
            @ApiParam(value = "上下架状态,0:下架，1:上架",required = true) @PathVariable("status") Integer status,
            @ApiParam(value = "中药id", required = true) Long id){
        chineseMedicineService.StartOrStop(status,id);
        return ResponseResult.success();
    }

    /**
     * 新增药品
     * @param chineseMedicineDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增中药")
    public ResponseResult save(@RequestBody ChineseMedicineDTO chineseMedicineDTO){
        chineseMedicineService.save(chineseMedicineDTO);
        return ResponseResult.success();
    }

    /**
     * 修改中药
     * @param chineseMedicineDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改中药")
    public ResponseResult update(@RequestBody ChineseMedicineDTO chineseMedicineDTO){
        chineseMedicineService.updateChineseMedicine(chineseMedicineDTO);
        return ResponseResult.success();
    }

    /**
     * 回显数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("回显数据，根据id查询中药")
    public ResponseResult<ChineseMedicineVO> ChineseMedicineSelectUpdateById(@PathVariable Long  id){
        ChineseMedicineVO chineseMedicineVO = chineseMedicineService.ChineseMedicineSelectUpdateById(id);
        return ResponseResult.success(chineseMedicineVO);
    }

    @DeleteMapping
    @ApiOperation("中药批量删除")
    public ResponseResult DeleteChineseMedicine(@RequestParam List<Long> ids){
        chineseMedicineService.deleteChineseMedicine(ids);
        return ResponseResult.success();
    }
}
